<?php
/**
 * MongoDig
 *
 * @copyright  Copyright (c) 2010 lanyanguang (http://www.lanyg.com)
 * @license    GNU General Public License 2.0
 * @version    $Id$
 */

/** 初始化 */
require_once 'init.php';

//判断是否登录
if(is_login()){
 	header("Location:" . $config['site_url'] . '/index.php');
	exit;
}

//页面提交处理
if(isset($_POST['Submit'])){
	$username = trim($_POST['username']);
	$password = trim($_POST['password']);
	if(!empty($username) && !empty($password)){
		include_logic('user');
		if($user = user_find_one(array('username'=>$username,'password'=>$password))){
			$_SESSION['user_id'] = $user['_id'];
			header('Location:'.$config['site_url'].'/index.php');
			exit;
		}
	}
}

$_GLOBAL['page_title'] = 'Login';

//载入登录页面
include_template('login');